package com.example.javapoint.threads.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolExample2 {
    private final static int MAX_TH = 3; // 固定大小

    public static void main(String[] args) {
        // 创建对象实例
        Runnable rb1 = new Tasks("task 1");
        Runnable rb2 = new Tasks("task 2");
        Runnable rb3 = new Tasks("task 3");
        Runnable rb4 = new Tasks("task 4");
        Runnable rb5 = new Tasks("task 5");

        // 初始化线程池大小
        ExecutorService executorService = Executors.newFixedThreadPool(MAX_TH);
        // 执行任务
        executorService.execute(rb1);
        executorService.execute(rb2);
        executorService.execute(rb3);
        executorService.execute(rb4);
        executorService.execute(rb5);

        executorService.shutdown(); // 关闭服务

    }
}
